aboutsummaryrefslogtreecommitdiffstats
path: root/src/app/groups/[groupId]
diff options
context:
space:
mode:
authorSebastien Castiel <sebastien@castiel.me>2023-12-07 11:11:53 -0500
committerSebastien Castiel <sebastien@castiel.me>2023-12-07 11:11:53 -0500
commit6611e3a187e5398f686449938b7cf1ddbfcb5392 (patch)
tree0fae44f29faf8efa68bcdb113ae1ca003cbd024b /src/app/groups/[groupId]
parentec981fd237a50dfc547d8c162b22f4e1a691c9fc (diff)
Store amounts as cents
Diffstat (limited to 'src/app/groups/[groupId]')
-rw-r--r--src/app/groups/[groupId]/balances-list.tsx69
-rw-r--r--src/app/groups/[groupId]/expenses/expense-list.tsx2
-rw-r--r--src/app/groups/[groupId]/reimbursement-list.tsx10
-rw-r--r--src/app/groups/[groupId]/save-recent-group.tsx2
4 files changed, 39 insertions, 44 deletions
diff --git a/src/app/groups/[groupId]/balances-list.tsx b/src/app/groups/[groupId]/balances-list.tsx
index 26092ec..0e321bb 100644
--- a/src/app/groups/[groupId]/balances-list.tsx
+++ b/src/app/groups/[groupId]/balances-list.tsx
@@ -15,51 +15,38 @@ export function BalancesList({ balances, participants, currency }: Props) {
return (
<div className="text-sm">
- {participants.map((participant) => (
- <div
- key={participant.id}
- className={cn(
- 'flex',
- balances[participant.id]?.total >= 0 || 'flex-row-reverse',
- )}
- >
+ {participants.map((participant) => {
+ const balance = balances[participant.id]?.total ?? 0
+ const isLeft = balance >= 0
+ return (
<div
- className={cn(
- 'w-1/2 p-2',
- balances[participant.id]?.total >= 0 && 'text-right',
- )}
+ key={participant.id}
+ className={cn('flex', isLeft || 'flex-row-reverse')}
>
- {participant.name}
- </div>
- <div
- className={cn(
- 'w-1/2 relative',
- balances[participant.id]?.total >= 0 || 'text-right',
- )}
- >
- <div className="absolute inset-0 p-2 z-20">
- {currency} {(balances[participant.id]?.total ?? 0).toFixed(2)}
+ <div className={cn('w-1/2 p-2', isLeft && 'text-right')}>
+ {participant.name}
+ </div>
+ <div className={cn('w-1/2 relative', isLeft || 'text-right')}>
+ <div className="absolute inset-0 p-2 z-20">
+ {currency} {(balance / 100).toFixed(2)}
+ </div>
+ {balance !== 0 && (
+ <div
+ className={cn(
+ 'absolute top-1 h-7 z-10',
+ isLeft
+ ? 'bg-green-200 left-0 rounded-r-lg border border-green-300'
+ : 'bg-red-200 right-0 rounded-l-lg border border-red-300',
+ )}
+ style={{
+ width: (Math.abs(balance) / maxBalance) * 100 + '%',
+ }}
+ ></div>
+ )}
</div>
- {balances[participant.id]?.total !== 0 && (
- <div
- className={cn(
- 'absolute top-1 h-7 z-10',
- balances[participant.id]?.total > 0
- ? 'bg-green-200 left-0 rounded-r-lg border border-green-300'
- : 'bg-red-200 right-0 rounded-l-lg border border-red-300',
- )}
- style={{
- width:
- (Math.abs(balances[participant.id]?.total ?? 0) /
- maxBalance) *
- 100 +
- '%',
- }}
- ></div>
- )}
</div>
- </div>
- ))}
+ )
+ })}
</div>
)
}
diff --git a/src/app/groups/[groupId]/expenses/expense-list.tsx b/src/app/groups/[groupId]/expenses/expense-list.tsx
index 0c03756..1ba7df7 100644
--- a/src/app/groups/[groupId]/expenses/expense-list.tsx
+++ b/src/app/groups/[groupId]/expenses/expense-list.tsx
@@ -53,7 +53,7 @@ export function ExpenseList({
</div>
<div className="flex items-center">
<div className="tabular-nums whitespace-nowrap font-bold">
- {currency} {expense.amount.toFixed(2)}
+ {currency} {(expense.amount / 100).toFixed(2)}
</div>
<Button size="icon" variant="link" className="-my-2" asChild>
<Link href={`/groups/${groupId}/expenses/${expense.id}/edit`}>
diff --git a/src/app/groups/[groupId]/reimbursement-list.tsx b/src/app/groups/[groupId]/reimbursement-list.tsx
index e8400ca..54ee9d7 100644
--- a/src/app/groups/[groupId]/reimbursement-list.tsx
+++ b/src/app/groups/[groupId]/reimbursement-list.tsx
@@ -16,6 +16,14 @@ export function ReimbursementList({
currency,
groupId,
}: Props) {
+ if (reimbursements.length === 0) {
+ return (
+ <p className="px-6 text-sm pb-6">
+ It looks like your group doesn’t need any reimbursement 😁
+ </p>
+ )
+ }
+
const getParticipant = (id: string) => participants.find((p) => p.id === id)
return (
<div className="text-sm">
@@ -35,7 +43,7 @@ export function ReimbursementList({
</Button>
</div>
<div>
- {currency} {reimbursement.amount.toFixed(2)}
+ {currency} {(reimbursement.amount / 100).toFixed(2)}
</div>
</div>
))}
diff --git a/src/app/groups/[groupId]/save-recent-group.tsx b/src/app/groups/[groupId]/save-recent-group.tsx
index e55d7c8..084681a 100644
--- a/src/app/groups/[groupId]/save-recent-group.tsx
+++ b/src/app/groups/[groupId]/save-recent-group.tsx
@@ -12,7 +12,7 @@ type Props = {
export function SaveGroupLocally({ group }: Props) {
useEffect(() => {
saveRecentGroup(group)
- }, [])
+ }, [group])
return null
}